<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>文章设置</title>
    <script type="text/javascript">
      var sysMsgId;
      var sysMsgDS;
      
      Ext.onReady(function(){
        //文章设置---------------------------------------------------------
        //生成有关文章的Grid
        sysMsgDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: pageSize
          },
          proxy: new Ext.data.HttpProxy({
            url: '/sys_msg/getAllSysMsgs'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'title'
            },{
              name: 'is_new'
            },{
              name: 'sub_type'
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }])
        });
        var sysMsgSM = new Ext.grid.CheckboxSelectionModel();
        var sysMsgCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),sysMsgSM,{
              header: 'id',
              dataIndex: 'id',
              width: 40
            }, {
              header: '标题',
              dataIndex: 'title',
              width:410
            }, {
              header: '文章类型',
              dataIndex: 'sub_type',
              width:110
            }, {
              header: '状态',
              dataIndex: 'is_new',
              renderer: readStatusRender,
              width:70
            },{
              header: '生成日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 130
            },{
              header: '阅读日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 130
            }]});
        
        var sysMsgGrid =  new Ext.grid.GridPanel({
          ds: sysMsgDS,
          cm: sysMsgCM,
          sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
          width: screenWidth-190,
          height: 345,
          iconCls: 'icon-grid',
          //collapsible: true,
          //animCollapse: false,
          //frame: true,
          //title: '文章列表',
          bbar: new Ext.PagingToolbar({
            pageSize: pageSize,
            store: sysMsgDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })
        });
        
        sysMsgDS.load();

        sysMsgGrid.on('rowdblclick', function(gridPanel, rowIndex, e){
          sysMsgId = sysMsgDS.getAt(rowIndex).get('id');
          Ext.Ajax.request({
            url : '/sys_msg/getMsgById',
            success : function (result, request) {
              content.setValue(Ext.util.JSON.decode(result.responseText).info);
              sysMsgDS.load();
              //调用全局函数改变可读数值
              synUnreadSysMsg();
            },
            failure : function (result, request){
              Ext.MessageBox.show({
                title: '消息',
                msg: "通讯失败，请从新操作",
                buttons: Ext.MessageBox.OK,
                icon: Ext.MessageBox.WARNING
              });
            },
            method : 'GET',
            params : {
              id : sysMsgId
            }
          });
        });

        var content = new Ext.form.HtmlEditor({
          fieldLabel: '内容',
          name: 'content',
          height:335,
          width: screenWidth-190,
          anchor: '100%'
        });
        
        //总的panel
        var workbenchPanel = new Ext.Panel({
          width: screenWidth-175,
          height: screenHeight-215,
          frame:false,
          layout:'table',
          layoutConfig: {columns:1},
          defaults:{margins:'5 5 5 5'},
          items:[sysMsgGrid,content]
        });
        
        workbenchPanel.render("sysMsg_list_workbench");
        
      })
    </script>
  </head>
  <body>
    <div id="sysMsg_list_workbench"></div>
  </body>
</html>
